package com.jf.cloud.delivery.feign;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jf.cloud.api.delivery.feign.SameCityFeignClient;
import com.jf.cloud.api.delivery.vo.SameCityVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.delivery.model.SameCity;
import com.jf.cloud.delivery.service.SameCityService;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Hidden
public class SameCityFeignClientController implements SameCityFeignClient {

    @Autowired
    private SameCityService sameCityService;

    @Override
    public ServerResponseEntity<Void> clearPositionInfo(Long shopId) {
        SameCity sameCity = new SameCity();
        sameCity.setShopId(shopId);
        sameCity.setPositionInfo("[]");
        sameCityService.updateByShopId(sameCity);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<SameCityVO> getSameCityByShopId(Long shopId){
        SameCity sameCity = sameCityService.getSameCityByShopId(shopId);
        SameCityVO SameCityVO = JSONObject.parseObject(JSON.toJSONString(sameCity), SameCityVO.class);
        return ServerResponseEntity.success(SameCityVO);
    }
}
